<template>
  <!-- 底部部分 -->
  <!-- 也可以直接在父组件Todofooter标签中添加 v-if="list.length"  初始没有list时，初始值为false，直接不创建Todofooter -->
  <footer class="footer" v-show="list.length > 0">
    <span class="todo-count"
      ><strong>{{ sy }}</strong
      >剩余</span
    >
    <ul class="filters">
      <li>
        <a
          @click.prevent="filterType('all')"
          :class="{ selected: value === 'all' }"
          href="#/"
          >全部</a
        >
      </li>
      <li>
        <a
          @click.prevent="filterType('active')"
          :class="{ selected: value === 'active' }"
          href="#/active"
          >进行中</a
        >
      </li>
      <li>
        <a
          @click.prevent="filterType('completed')"
          :class="{ selected: value === 'completed' }"
          href="#/completed"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" v-show="clearIsdone" @click="clear11">
      清除已完成
    </button>
  </footer>
</template>

<script>
export default {
  data() {
    return {
      // type: 'all',
    }
  },
  props: {
    value: String,
    // type: {
    //   type: String,
    // },
    list: {
      type: Array,
      required: true,
    },
  },
  computed: {
    sy() {
      return this.list.filter((item) => item.isDone === false).length
    },
    clearIsdone() {
      // 此处用find和some方法皆可
      return this.list.find((item) => item.isDone)
    },
  },
  methods: {
    clear11() {
      this.$emit('clear')
    },
    filterType(type) {
      this.$emit('input', type)
    },
  },
}
</script>
